﻿@model LbangCMS.Areas.Admin.Models.CategoryModel
@{
    ViewBag.Title = "Edit";
    Layout = "~/Areas/Admin/Views/Shared/_FormLayout.cshtml";
}


<div class="panel">
    @using (Html.BeginForm("Edit", "ProductCategory", FormMethod.Post, new { @id = "form", @class = "form-horizontal" }))
    {
        if (Model != null)
        {
            <input type="hidden" name="Id" value="@Model.ID" />
        }
        <div class="form-group">
            <label class="col-md-2 control-label required">分类名</label>
            <div class="col-md-4">
                @Html.TextBoxFor(model => model.Name, new { @class = "form-control" })
            </div>
        </div>


        <div class="form-group">
            <label class="col-md-2 control-label required">排序号</label>
            <div class="col-md-4">
                @Html.TextBoxFor(model => model.SortIndex, new { @class = "form-control" })
            </div>
        </div>

        <div class="form-group">
            <div class="col-md-offset-4 col-md-4">
                <input type="button" id="submit" class="btn btn-primary" onclick="submitForm()" value="保存">
            </div>
        </div>
    }
</div>
@section script {
    <script type="text/javascript">
        $().ready(function () {
            $("#form").validate({
                rules: {
                    Name: {
                        required: true,
                        minlength: 2,
                    },
                    SortIndex: {
                        required: true,
                        isInteger: true,
                    }
                },
                messages: {
                    Name: {
                        required: "请输入分类名",
                        minlength: "分类名必须是2个以上的字符",
                    },
                    SortIndex: {
                        required: "请输入排序号",
                        isInteger: "排序号必须是数字",
                    },
                },
                onfocusout: function(element) { $(element).valid(); },
                errorPlacement: function (error, element) {
                    if (element.is(":radio")) {
                        error.appendTo(element.parent());
                    }
                    if (element.is(":checkbox"))
                        error.appendTo(element.parent());
                    else
                        error.appendTo(element.parent());
                }

            });
        })

        function submitForm(msg) {
            com.submitForm({
                isValid: true,
                $form: $("#form"),
                success: function (result) {
                    if (result.success) {
                        layer.msg("保存成功");
                        parent.reload_data();
                        setTimeout("parent.layer.closeAll('iframe');", 500);
                    } else {
                        layer.alert(result.msg);
                    }
                }
            });
        }
    </script>
}
